<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>登录注册-生命体征监测云平台</title>
		<link rel="shortcut icon" href="static/logo.ico" />
		<link rel="stylesheet" href="static/css/style.css">
		<script type="text/javascript" src="static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="static/layui/css/layui.css" />
		<script type="text/javascript" src="static/js/vue.js"></script>
		<script type="text/javascript" src="static/js/axios.min.js"></script>
		<script src="static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script>
			// localStorage.clear()
			// $(function() {
			//  $("#denglu").click(function(){
			//      console.log('111111111111111111')
			//       var logintypes=   $('#types').val();
			//      console.log('111111111111111111')
			//                  if(logintypes==1){
			//                      window.location='home.html'
			//                      localStorage["logintypes"]=1;
			//                  }else if(logintypes==2){
			//                      window.location='index.html'
			//                      localStorage["logintypes"]=2;
			//                  }else if(logintypes==3){
			//                      window.location='index.html'
			//                      localStorage["logintypes"]=3;
			//                  }else{
			//          console.log('00000000000')
			//                  }
			//            });
			// });   
		</script>

	</head>
	<body>

		<div class="container " id="app">
			<!-- Sign Up -->
			<div class="container__form container--signup">
				<form action="#" class="form" id="form1">
					<h2 class="form__title">注册</h2>
					<input type="text" name="mobile" autocomplete="off" pattern="^1[345678][0-9]{9}$" required
						placeholder="手机号" class="input" id="rloginName" />
					<!-- 
					<input type="email" placeholder="邮箱" class="input" id="remail"> -->
					<input type="password" placeholder="密码" class="input" id="rpassword">
					<input type="password" placeholder="确认密码" class="input" id="rrpassword">
					<!-- 
					<input type="text" placeholder="设备号" class="input" id="requipment"> -->
				</form>
				<button class="btn" @click="regeist" style="position: absolute;top: 82%;left: 28%;">注册</button>
			</div>
			<!-- Sign In -->
			<div class="container__form container--signin">
				<form action="#" class="form" id="form2">
					<h2 class="form__title">登录</h2>
					<!-- <input type="tel" placeholder="手机号 " class="input"> -->
					<input type="text" name="mobile" autocomplete="off" pattern="^1[345678][0-9]{9}$" required
						placeholder="手机号" class="input" id="loginName" />
					<input type="password" placeholder="密码" class="input" id="password">
					<select name="types" lay-verify="required" id="types"
						style="background-color: #fff; border: none;padding: 0.9rem 0.9rem; margin: 0.5rem 0; width: 111%;">
						<option value="">请选择登录类型</option>
						<option value="1">家庭用户</option>
						<option value="2">社区管理</option>
						<option value="3">医院管理</option>
					</select>
					<!-- <a href="#" class="link">忘记密码?</a> -->
				</form>
				<button class="btn" id="denglu" @click="login"
					style="position: absolute;top: 82%;left: 28%;">登录</button>
			</div>
			<!-- Overlay -->
			<div class="container__overlay">
				<div class="overlay">
					<div class="overlay__panel overlay--left">
						<button class="btn" id="signIn">登录</button>
					</div>
					<div class="overlay__panel overlay--right">
						<button class="btn" id="signUp">注册</button>
					</div>
				</div>
			</div>
		</div>

		<script type="text/javascript" src="static/js/config.js"></script>
		<script>
			var vm = new Vue({
				el: '#app', //设置当前vue对象可以操作数据的范围,注意不要把vue对象绑定到body中，因为这样，vue需要控制整个页面的内容，效率太低了
				data: {},
				methods: {
					login: function() {
						var logintypes = parseInt($('#types').val());
						var loginName = $('#loginName').val();
						var password = $('#password').val();
						axios.get(url + "/user/userInfo/newLoginPwd?loginType=" + logintypes + "&loginName=" +
								loginName + "&password=" + password)
							.then(res => {
								console.log(res.data)
								var data = res.data;
								var message = res.data.message;
								if (res.data.code == 0) {
									layer.msg(message, {
										time: 2000,
										end: function() {
											if (logintypes == 1) {
												localStorage["logintypes"] = 1;
												localStorage["loginName"] = loginName;
												var defaultEqu = res.data.defaultEqu;
												if (defaultEqu != null) {
													var equName = defaultEqu.equName;
													var userId = defaultEqu.userId;
													localStorage["equName"] = equName;
													localStorage["userName"] = userId;
													window.location = 'home.html'
												} else {
													localStorage["equName"] = '';
													layer.confirm('未绑定设备，请绑定设备！', {
														btn: ['确定', '取消'] //按钮
													}, function() {
														window.location = 'equipment.html'
													}, function() {
														window.location = 'home.html'
													});
												}
											} else if (logintypes == 2) {
												window.location = 'index.html'
												localStorage["logintypes"] = 2;
												localStorage["loginName"] = loginName;
											} else if (logintypes == 3) {
												window.location = 'index.html'
												localStorage["logintypes"] = 3;
												localStorage["loginName"] = loginName;
											} else {
												layer.msg(message)
											}
										}
									})
								} else {
									layer.msg(message)
								}
							})
							.catch((error) => {
								//报错
							});
					},
					regeist: function() {
						var rloginName = $('#rloginName').val();
						var rpassword = $('#rpassword').val();
						var rrpassword = $('#rrpassword').val();
						if (rloginName == '' || rloginName == null || rloginName == 'undefined') {
							layer.msg('请输入正确的手机号！')
						} else if (rpassword != rrpassword) {
							layer.msg('密码和确认密码不一样！')
						} else {
							axios.get(url + "/user/userInfo/insertUser?loginName=" + rloginName + "&password=" +
									rpassword)
								.then(res => {
									console.log(res)
									var code = res.data.code;
									var message = res.data.message;
									layer.msg(message, {
										time: 2000,
										end: function() {
											location.href = 'login.html'
										}
									})
								})
								.catch((error) => {
									//报错
								});
						}
					},
				}
			})
		</script>
		<script src="static/js/script.js"></script>
	</body>
</html>
